package TcpDemon01;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

// 服务端
public class TcpServerDemon01{
    public static void main(String[] args) {
        try (
                // 1. 有一个地址
                ServerSocket serverSocket=new ServerSocket(9999);
                // 2. 连接客户端
                Socket socket=serverSocket.accept();
                // 3. 读取数据
                InputStream is=socket.getInputStream();
                // 管道流
                ByteArrayOutputStream baos=new ByteArrayOutputStream();
                ){

            byte[] buffer=new byte[1024];
            int len;
            while((len=is.read(buffer))!=-1){
                baos.write(buffer,0,len);
            }
            System.out.println(baos.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}